home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / asm / SEKAconvert.lha / SEKAconvert.c < prev    next >
C/C++ Source or Header  |  1992-09-20  |  3KB  |  119 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4.  
  5. main(argc,argv)
  6. char **argv;
  7. {
  8.     FILE *in;
  9.     FILE *out;
  10.     char mystring[200],tempstring[200];
  11.     int len,firstchar,label,comment,equal;
  12.     register int i;
  13.     register char ch;
  14.     unsigned int li;
  15.     
  16.     printf ("SEKA to Metacomco translator\nBy J-F Stenuit\n");
  17.     if (argc != 3) {
  18.         printf ("Usage: %s infile outfile\n",argv[0]);
  19.         exit(0);
  20.     }
  21.     if ((in = fopen(argv[1],"r")) == NULL) {
  22.         printf ("Unable to open input file %s\n",argv[1]);
  23.         _exit(0);
  24.     }
  25.     if ((out = fopen(argv[2],"w")) == NULL) {
  26.         printf ("Unable to open output file %s\n",argv[2]);
  27.         fclose (in);
  28.         _exit(0);
  29.     }
  30.     li = 0;
  31.     for (;;) {
  32.         if (fgets(mystring,197,in)==NULL)
  33.             break;
  34.         len = -1;
  35.         firstchar = -1;
  36.         label = -1;
  37.         comment = -1;
  38.         equal = -1;
  39.          
  40.         for (i=0 ; i<=198 ; i++) {
  41.             ch = mystring[i];
  42.             if ((firstchar == -1) && (isgraph(ch)))
  43.                 firstchar = i;
  44.             if ((label == -1) && (ch == ':') && (comment == -1))
  45.                 label = i;
  46.             if ((equal == -1) && (ch == '=') && (comment == -1) && (i > 0))
  47.                 equal = i; 
  48.             if ((comment == -1) && (ch == ';'))
  49.                 comment = i;
  50.             if (ch == 0)
  51.                 break;
  52.         }
  53.         len = i;
  54.         
  55.         /* add ";" on start of comment */
  56.         ch = tolower(mystring[firstchar]);
  57.         if (((ch<'a') || (ch>'z')) && (ch != ';')) {
  58.             for (i=len+1 ; i>0 ; i--)
  59.                 mystring[i] = mystring[i-1];
  60.             mystring[0] = ';';
  61.             comment = 0;
  62.             len++;
  63.         }
  64.  
  65.         /* pad char before comment */
  66.         if ((comment > 0) && (isgraph(mystring[comment-1]))) {
  67.             for (i=len+1 ; i>comment ; i--)
  68.                 mystring[i] = mystring[i-1];
  69.             mystring[comment] = ' ';
  70.             len++;
  71.         }
  72.         
  73.         /* convert blk to dcb */
  74.         strcpy(tempstring,mystring);
  75.         strlwr(tempstring);
  76.         i = 0;
  77.         if (label != -1)
  78.             i = label;
  79.         while ((i < len) && (tempstring[i] != ';')) {
  80.             if (tempstring[i] == 'b')
  81.                 if (tempstring[i+1] == 'l')
  82.                     if (tempstring[i+2] == 'k')
  83.                         memcpy(&mystring[i],"dcb",3);
  84.             i++;
  85.         }
  86.         
  87.         /* pad char after label */
  88.         if (label != -1)
  89.             if (mystring[label+1] != ' ') {
  90.                 for (i=len+1 ; i>label ; i--)
  91.                     mystring[i] = mystring[i-1];
  92.                 mystring [label+1] = ' ';
  93.             }
  94.         
  95.         /* pad char before instruction */
  96.         if ((firstchar == 0) && (mystring[0] != ';') &&
  97.             (label == -1) && (equal == -1)) {
  98.             for (i=len+1 ; i>0 ; i--)
  99.                 mystring[i] = mystring[i-1];
  100.             mystring[0] = ' ';
  101.         }
  102.         
  103.         
  104.         /* write resulting string */
  105.         if (fputs(mystring,out) == EOF) {
  106.             printf ("Error writing to file %s\n",argv[2]);
  107.             fclose(in);
  108.             fclose(out);
  109.             unlink(argv[2]);
  110.             _exit(0);
  111.         }
  112.         printf ("\x0dline : %d",li);
  113.         li++;
  114.     }
  115.     printf("\n");
  116.     fclose(in);
  117.     fclose(out);
  118. }
  119.